// createRouter 函数用于创建路由实例对象
// createWebHistory 函数用于创建路由对象为history模式
import { createRouter, createWebHistory } from 'vue-router'

import login from '@/views/Login/index.vue'
import layout from '@/views/Layout/index.vue'
import category from '@/views/Category/index.vue'
import home from '@/views/Home/index.vue'
import subCategory from '@/views/SubCategory/index.vue'
import detail from '@/views/Details/index.vue'
import cartlist from '@/views/CartList/index.vue'
import checkout from '@/views/CheckOut/index.vue'
import pay from '@/views/Pay/index.vue'
import member from '@/views/Member/index.vue'
import userInfo from '@/views/Member/components/userInfo.vue'
import userOrder from '@/views/Member/components/userOrder.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: '首页',
      component: layout,
      children: [
        {
          path: '',
          name: '首页主页',
          component: home,
        },
        {
          path: 'category/:id',
          name: '商品分类',
          component: category,
        },
        {
          path: 'category/sub/:id',
          name: '二级商品分类',
          component: subCategory,
        },
        {
          path: 'detail/:id',
          name: '商品详情页',
          component: detail,
        },
        {
          path: 'cartlist',
          name: '购物车列表',
          component: cartlist
        },
        {
          path: 'checkout',
          name: '结算页',
          component: checkout
        },
        {
          path: 'pay',
          name: '支付页',
          component: pay
        },
        {
          path: 'member',
          name: '会员中心',
          component: member,
          children: [
            {
              path: '',
              name: '个人中心',
              component: userInfo
            },
            {
              path: 'order',
              name: '我的订单',
              component: userOrder
            }
          ]
        }
      ]
    },
    {
      path: '/login',
      name: '登录页',
      component: login
    }
  ],
  // 定制路由滚动行为
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
